package gameengine;

import java.util.HashMap;
import java.util.Map;

public class GameMgr {
	
	public static final int STATE_MENU = 0;
	public static final int STATE_LIVES = 1;
	public static final int STATE_GAME = 2;
	public static final int STATE_PAUSE = 3;
	public static final int STATE_HISCORE = 4;
	public static final int STATE_PREMENU = 5;
	public static final int STATE_HELP = 6;
	public static final int STATE_CREDITS = 7;
	public static final int STATE_LOAD = 8;
	public static final int STATE_GAME_LOSE = 9;
	public static final int STATE_GAME_WIN = 10;
	public static final int STATE_SCORE_ENTER = 11;

	public static final int MENU_COUNT = 7;
	public static final int NAME_SIZE = 4;

	private int score;
	private int gameState;
	private int stage;
	private int lives;
	private Map<String,Long> timeMap;
	private int menuSel;
	private boolean difficulty;
	private int stageLen;
	private String name;
	
	public GameMgr(){
		difficulty = false;
		menuSel = 0;
		score = 0;
		stage = 0;
		lives = 3;
		gameState = STATE_PREMENU;
		resetName();
		timeMap = new HashMap<String, Long>();
	}
	
	public Long getTime(String key){
		return timeMap.get(key);
	}
	
	public void setTime(String key, long s){
		timeMap.put(key,s);
	}
	
	public void removeTime(String key){
		timeMap.remove(key);
	}
	
	
	public int getLives(){
		return lives;
	}
	
	public void setLives(int s){
		lives = s;
	}
	
	public void resetLives(){
		lives = 3;
	}
	
	public void decLives(){
		lives--;
	}
	
	
	public int getGameState(){
		return gameState;
	}
	
	public void setGameState(int s){
		gameState = s;
	}
	
	public int getScore(){
		return score;
	}
	
	public void addScore(int v){
		score += v;
	}
	
	public void setScore(int s){
		score = s;
	}
	
	public void resetScore(){
		score = 0;
	}
	
	public int getMenuSelect(){
		return menuSel;
	}
	
	public void moveMenuSelect(int m, int max){
		menuSel += m + max;
		menuSel %= max;
	}
	
	public void setMenuSelect(int menuSel){
		this.menuSel = menuSel;
	}
	
	public void toggleDiff(){
		difficulty = !difficulty;
	}
	
	public int getStage(){
		return stage;
	}
	
	public void setStage(int s){
		stage = s;
	}
	
	public void incStage(){
		stage++;
	}
	
	public String getDifficultyString(){
		if (difficulty)
			return "HARD";
		else
			return "EASY";
	}
	
	public boolean getDifficulty(){
		return difficulty;
	}

	public int getStageLen() {
		return stageLen;
	}

	public void setStageLen(int stageLen) {
		this.stageLen = stageLen;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void resetName() {
		name = "";
		for (int i = 0; i < NAME_SIZE; i++) {
			name += "A";			
		}
	}
	
	public void moveName(int i, int delta){
		char change = (char) (name.charAt(i) + delta);
		if(change < 'A')
			change = 'Z';
		else if (change > 'Z' ) 
			change = 'A';
		
		String newName = "";
		for (int k = 0; k < NAME_SIZE; k++) {
			if (k == i)
				newName += change;
			else
				newName += name.charAt(k);
		}
		name = newName;
	}
}
